#article-table
	table.table.table-striped.table-bordered(data-bind="foreach:articles")
		tr(data-bind="attr:{id:'tr'+id}")
			td
				img.img-thumbnail.pull-left(data-bind="attr:{src:'/img?src='+cover,id:'img'+id}",style="width:350px;")
				span
					strong(data-bind="text:title")
					|&nbsp;&nbsp;
					p(data-bind="text:digest")

					span 作者：
						span(data-bind="text:nickname")
					br
					span 时间：
						span(data-bind="text:datetime")
					br
					br
					a(data-bind="attr:{href:contenturl}",target="_blank") 查看原文
					br
					br
					.btn-group.btn-group-sm
						button.btn.btn-primary(data-bind="click:$root.approveArticle.bind($context,id)") 通过
						//- button.btn(data-bind="click:$root.activeAccount.bind($context,id,active),css:{'btn-warning':active==0,'btn-success':active>0},text:(active?'启用':'禁用')")
						button.btn.btn-danger(data-bind="click:$root.deleteArticle.bind($context,id)") 删除
					//- small(data-bind="text:signature")

	ul.pagination(data-bind="foreach:pages")
		li(data-bind="if:Math.abs($root.page()-$data)<10,css:{active:$root.page()==$data}")
			a(href="#",data-bind="click:function(){$root.paginate($data)},text:$data+1")

script
	var ArticleVM = function(){
		var self = this;
		self.articles = ko.observableArray([]);
		self.pages = ko.observableArray([]);
		self.page = ko.observable(0);
		self.count = ko.observable(0);
		self.fetch = function(){
			$('#loading').modal('show')
			$.ajax({
					url:'articles?page='+self.page(),
					success:function(data){
						self.count(data.count);
						self.pages(ko.utils.range(0,Math.ceil(data.count/50)));
						self.articles(data.articles);
						$('#loading').modal('hide');
					}
				})
		}

		self.paginate = function(page){
			self.page(page);
			self.fetch();
		}

		self.deleteArticle = function(id){
			$('#loading').modal('show');
			$.ajax({
				url:'articles/'+id+'/delete',
				success:function(){
					$('#tr'+id).hide();
					$('#loading').modal('hide');
				}	
			});
		}

		self.approveArticle = function(id){
			$('#loading').modal('show');
			$.ajax({
				url:'articles/'+id+'/approve?approve='+1,
				success:function(){
					$('#tr'+id).hide();
					$('#loading').modal('hide');
				}	
			})
		}

	}
	window.articleVM = new ArticleVM();
	articleVM.fetch();
	ko.applyBindings(articleVM,document.getElementById('article-table'));